package net.xdclass.controller;


import net.xdclass.controller.request.AccountLoginRequest;
import net.xdclass.controller.request.AccountRegisterRequest;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.service.AccountService;
import net.xdclass.service.FileService;
import net.xdclass.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/api/account/v1")
public class AccountController {


    @Autowired
    private FileService fileService;

    @Autowired
    private AccountService accountService;

    @RequestMapping("upload")
    public JsonData uploadUserImg(@RequestPart("file") MultipartFile file) {
        String result = fileService.uploadUserImg(file);
        return result != null ? JsonData.buildSuccess(result) : JsonData.buildResult(BizCodeEnum.FILE_UPLOAD_USER_IMG_FAIL);
    }

    @RequestMapping("register")
    public JsonData register(@RequestBody AccountRegisterRequest request) {
       JsonData jsonData = accountService.register(request);
        return jsonData;
    }

    @RequestMapping("login")
    public JsonData login(@RequestBody AccountLoginRequest request){

            JsonData jsonData = accountService.login(request);

        return jsonData;
    }

}

